from typing import List

class Solution:
    def putMarbles(self,wt:List[int],k:int)->int:
        for i in range(len(wt)-1):
            wt[i]+=wt[i+1]
        wt.pop()
        wt.sort()
        return sum(wt[len(wt)-k+1:])-sum(wt[:k-1])

test = Solution()
weights=[1,3,5,1]
k=2
print(test.putMarbles(weights,k))